<?php 
class BloggView
{
	private $title = "title";
	private $post = "post";
	private $submit = "submit";
	const TO_LONG = 0;
	const TITLE_USED = 1;
	const POST_PASSED = 2;
	const POST_FAILED = 3;
	
	public function showPost(Blogg $blogg)
	{
		$listLink = NavigationView::getPostList();
		$title =$blogg->getTitle();
		$date = $blogg->getDate();
		$post = $blogg->getPost();
		return "
				<div>
						<h1>$title</h1>

						$post
						</br>
						<h3>$date</h3>
						<a href='$listLink'>Back to list</a>
				</div> 
		";
		
	}
	public function ShowListOfPosts (BloggArray $bloggArray)
	{
		$ret = "<h2>Posts</h2>";
		$ret .= "<ul>";
		foreach ($bloggArray->get() as $blogg) {
				$linkToPost = NavigationView::getPostLink($blogg);
				$ret .= "<li><a href='$linkToPost'>". $blogg->getTitle() . "</a></li>"; 
		}
		$ret .= "</ul>";
		return $ret;
	}

	public function DoNewPost()
	{
		$html=
			"<div>
				<h3>New Post</h3>
					<form method ='POST' action='index.php?page=newpost'/>
						<h4>Title</h4>
								<input type='text' name='$this->title'/></br>
						Post:</br>
								<textarea type='text' rows='10' cols='30' name='$this->post'></textarea></br>
						<input type='submit' value='Submit' name='$this->submit'/>
					</form>
			</div>";
		return $html;
	} 
	public function PostTitle()
	{
		if (isset($_POST[$this->title])==true)
		{
			return $_POST[$this->title];
		}
		return null;
	}
	public function NewPost()
	{
		if (isset($_POST[$this->post])==true)
		{
			return $_POST[$this->post];
		}
		return null;
	}

	public function TriedToSubmit()
	{ 
		if (isset($_POST[$this->submit]) == true) 
		{
			return true;
		}
		return false;
	}
	public function Message($status)
	{
		switch ($status)
		{
			case self::TO_LONG:
				return"<p>To many letters</p>";
				break;
			case self::TITLE_USED:
				return"<p>The Title is used</p>";
				break;
			case self::POST_PASSED:
				return"<p>You posted was a sucsess</p>";
				break;
			case self::POST_FAILED:
				return"<p>You post was a failure</p>";
				break;
				default;
				break;
		}
	}
}